package cn.smile.controller.basic;

import cn.smile.bean.dto.basic.ExpenseBillDTO;
import cn.smile.bean.form.basic.bill.ExpenseAddForm;
import cn.smile.bean.form.basic.bill.QueryExpenseForm;
import cn.smile.business.basic.IExpenseBillService;
import cn.smile.commons.response.MyResult;
import com.baomidou.mybatisplus.core.metadata.IPage;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

import jakarta.annotation.Resource;

@RestController
@RequestMapping("api/expenseBill")
public class ExpenseBillController {

    @Resource
    private IExpenseBillService service;

    @PostMapping(value = "addExpense")
    public MyResult<Boolean> addExpense(@Valid @RequestBody ExpenseAddForm form) {
        return MyResult.OK(service.addExpense(form));
    }

    @PostMapping(value = "getPage")
    public MyResult<IPage<ExpenseBillDTO>> getPage(@RequestBody QueryExpenseForm form){
        return MyResult.OK(service.getPage(form));
    }

    @GetMapping(value = "delExpense")
    public MyResult<Boolean> delExpense(@RequestParam("id") String id) {
        return MyResult.OK(service.delExpense(id));
    }

    @GetMapping(value = "getExpenseById")
    public MyResult<ExpenseBillDTO> getExpenseById(@RequestParam("id") String id){
        return MyResult.OK(service.getExpenseById(id));
    }
}
